import com.sun.prism.j2d.J2DPipeline;
import org.apache.log4j.Logger;
import redis.clients.jedis.Jedis;

import java.util.List;


/**+
 * Created by Administrator on 2017/5/5.
 */
public class RedisTest {
    public static Logger logger = Logger.getLogger(RedisTest.class);
    public static void main(String[] args){
        Jedis jedis = new Jedis("192.168.1.125",6379);
        System.out.println("Connection to server sucessfully");

        //查看服务是否运行
        System.out.println("Server is running: "+jedis.ping());

        //字符串练习
        jedis.set("lihao","lihao1111");
        System.out.println("The value is:"+jedis.get("lihao"));

        //列表list练习
        jedis.lpush("tutorial-list","redis");
        jedis.lpush("tutorial-list","mongodb");
        jedis.lpush("tutorial-list","mysql");
        List<String> list = jedis.lrange("tutorial-list",0,5);
        for(int i = 0; i<list.size();i++){
            System.out.println("Sorted string in redis list:"+list.get(i));
        }

//        //获取数据并输出
//        List<String> list = jedis.keys("*");
//        for(int i=0; i<list.size(); i++) {
//            System.out.println("List of stored keys:: "+list.get(i));
//        }

    }
}
